Skip to content

Add comprehensive unit tests across all modules#10

Merged
muk2 merged 1 commit intomainfrom
feature/comprehensive-testing
Feb 18, 2026
Merged

Add comprehensive unit tests across all modules#10
muk2 merged 1 commit intomainfrom
feature/comprehensive-testing

Conversation

@muk2
Copy link
Owner

@muk2 muk2 commented Feb 18, 2026

Summary

Establishes foundational test coverage for pgrsql, addressing the testing strategy outlined in #8. Adds 124 unit tests across all 6 existing source modules using inline #[cfg(test)] modules.

Test Coverage by Module

src/editor/buffer.rs — 50 tests

  • Construction: new(), Default, from_text() (empty, single-line, multi-line)
  • Text retrieval: text(), current_line(), line_count()
  • Insertion: single char, mid-line, newline, multiline text, tab, replaces selection
  • Deletion: backspace (middle, line-merge, beginning edge), delete (middle, line-merge, end edge), with selection
  • Cursor movement: left/right (with line wrapping), up/down (with clamping), line start/end, document start/end
  • Word movement: word-left, word-right, across line boundaries
  • Selection: start/get, same-line and multi-line text, select all, select line, delete selection
  • Utilities: clear, set_text, text round-trip, ensure_cursor_visible (scroll up/down)

src/editor/history.rs — 20 tests

  • Storage: add entry, consecutive duplicate prevention, whitespace-trimmed dedup, non-consecutive duplicates allowed, max entries trimming
  • Navigation: previous (returns last, navigates backward, stops at first), next (navigates forward, stops at last, returns None without prior previous), reset navigation, add resets navigation
  • Search: case-insensitive substring matching, no results
  • Serialization: serde_json round-trip

src/ui/theme.rs — 20 tests

  • Theme construction: dark theme (RGB < 50), light theme (RGB > 200), default is dark
  • Style helpers: normal style, header is bold, border focused vs unfocused, status styles (success/error/warning)
  • SQL keyword detection: case-insensitive matching, non-keywords rejected, DML/DDL/window/CTE categories
  • SQL type detection: case-insensitive matching, non-types rejected
  • List integrity: all keywords uppercase, all types uppercase, no duplicate keywords, no duplicate types

src/db/connection.rs — 18 tests

  • ConnectionConfig: default values, connection string generation, display string, special character escaping, all SSL modes
  • AWS RDS: host detection (positive/negative), auto-detect certs, explicit certs
  • ConnectionManager: construction
  • Utilities: quote_conn_value(), base64 decoding (with padding, without, with newlines)
  • Serialization: TOML round-trip, password skip_serializing

src/db/query.rs — 12 tests

  • CellValue display: Null, Bool, Int16/32/64, Float32/64, Text, Bytes, Json, Array, Unknown
  • CellValue display_width: width calculations
  • QueryResult: empty constructor, error constructor

src/db/schema.rs — 8 tests

  • TableType: icon() and label() for all 4 variants, equality
  • Clone: DatabaseInfo, SchemaInfo, TableInfo
  • Construction: ColumnDetails, IndexInfo

Design Decisions

  • Inline #[cfg(test)] modules — tests live alongside the code they test, following Rust convention
  • No database required — all tests are pure unit tests that don't require a running PostgreSQL instance
  • Zero dependencies added — tests use only existing crate dependencies (chrono, serde_json, etc.)
  • Zero clippy warnings — all tests pass cargo clippy cleanly

Test Results

test result: ok. 124 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Test plan

  • cargo test — 124 tests pass
  • cargo clippy — zero warnings
  • cargo fmt — properly formatted

Closes #8

🤖 Generated with Claude Code

Establishes foundational test coverage for pgrsql as outlined in issue #8.
Adds inline #[cfg(test)] modules to 6 existing source files covering
editor buffer operations, query history, theme/syntax detection,
database connection config, query result types, and schema introspection.

Closes #8

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@muk2 muk2 merged commit ec5fe23 into main Feb 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🧪 Epic: Comprehensive Testing Strategy for pgrsql (SQL Engine + Multi-Language + TUI)

1 participant